package com.karolak.stock.oscilator;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.Indicator;

public class DivOsc extends Oscilator {

	private Indicator input1;

	public DivOsc(String name, DataManager dataManager, Indicator input0, Indicator input1) {
		super(dataManager, 0, input0);
		this.input1 = input1;
		setName(name);
	}

	public DivOsc(DataManager dataManager, Indicator input0, Indicator input1) {
		super(dataManager, 0, input0);
		this.input1 = input1;
		setName(String.format("%s-%s-%s", super.getName(), getInput().getName(), getInput1().getName()));
	}

	@Override
	public double execute(double x) {
		double v0 = getDataManager().getLast(getInput().getName());
		double v1 = getDataManager().getLast(getInput1().getName());
		if (v1 == 0) {
			return 0;
		}
		double div = v0 / v1;
		return div;
	}

	public Indicator getInput1() {
		return input1;
	}
}
